package com.gettec.lims.client.bind;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.extjs.gxt.ui.client.binding.Converter;
import com.extjs.gxt.ui.client.binding.FieldBinding;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.Field;
import com.extjs.gxt.ui.client.widget.form.RadioGroup;

public class DateFieldBinding extends FieldBinding{

	public DateFieldBinding(Field field, String property) {

        super(field, property);
        if (field instanceof DateField) {
            final DateField combo = (DateField) field;
            setConverter(new Converter() {

                @Override
                public Object convertFieldValue(Object value) {
                    if (value !=null) {
                       Date d=(Date)value;
                     
                       java.sql.Date sqldate=new java.sql.Date(d.getTime());
                        return sqldate;
                    } else {
                        return value;
                    }
                }

                @Override
                public Object convertModelValue(Object value) {
                	  if (value !=null) {
                	  java.sql.Date d=(java.sql.Date)value;
                	  return new java.util.Date(d.getTime());
                	  }
                	  return value;
                    
                }

            });
        }
    
	}
	 public DateFieldBinding(Field field) {
		    this(field, field.getName());
		  }

}
